home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gdevdjet.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  14.8 KB  |  426 lines

  1. /* Copyright (C) 1989, 2000 Aladdin Enterprises.  All rights reserved.
  2.  
  3.    This program may be distributed as part of AFPL Ghostscript, under the
  4.    terms of the Aladdin Free Public License (the "License").
  5.  
  6.    AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No
  7.    author or distributor accepts any responsibility for the consequences of
  8.    using it, or for whether it serves any particular purpose or works at
  9.    all, unless he or she says so in writing.  Refer to the License for full
  10.    details.
  11.  
  12.    Every copy of AFPL Ghostscript must include a copy of the License,
  13.    normally in a plain ASCII text file named PUBLIC.  The License grants you
  14.    the right to copy, modify and redistribute AFPL Ghostscript, but only
  15.    under certain conditions described in the License.  Among other things,
  16.    the License requires that the copyright notice and this notice be
  17.    preserved on all copies.
  18.  
  19.    This program may also be distributed and/or modified under the terms of
  20.    the GNU General Public License as published by the Free Software
  21.    Foundation (the "GPL"); either version 2 of the GPL, or (at your option)
  22.    any later version.
  23.  
  24.    When distributed under the terms of the GPL, this program is distributed
  25.    in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
  26.    even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  27.    PURPOSE.  See the GPL for more details.
  28.  
  29.    If this program is being distributed under the terms of the GPL, you
  30.    should have received a copy of the GPL along with this program, normally
  31.    in a plain ASCII text file named COPYING; if not, write to the Free
  32.    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111
  33.    U.S.A.
  34.  */
  35.  
  36. /*$Id: gdevdjet.c,v 1.6 2000/09/19 19:00:12 lpd Exp $ */
  37. /* HP LaserJet/DeskJet driver for Ghostscript */
  38. #include "gdevprn.h"
  39. #include "gdevdljm.h"
  40.  
  41. /*
  42.  * Thanks for various improvements to:
  43.  *      Jim Mayer (mayer@wrc.xerox.com)
  44.  *      Jan-Mark Wams (jms@cs.vu.nl)
  45.  *      Frans van Hoesel (hoesel@chem.rug.nl)
  46.  *      George Cameron (g.cameron@biomed.abdn.ac.uk)
  47.  *      Nick Duffek (nsd@bbc.com)
  48.  * Thanks for the FS-600 driver to:
  49.  *    Peter Schildmann (peter.schildmann@etechnik.uni-rostock.de)
  50.  * Thanks for the LJIIID duplex capability to:
  51.  *      PDP (Philip) Brown (phil@3soft-uk.com)
  52.  * Thanks for the OCE 9050 driver to:
  53.  *      William Bader (wbader@EECS.Lehigh.Edu)
  54.  * Thanks for the LJ4D duplex capability to:
  55.  *    Les Johnson <les@infolabs.com>
  56.  */
  57.  
  58. /*
  59.  * You may select a default resolution of 75, 100, 150, 300, or
  60.  * (LJ4 only) 600 DPI in the makefile, or an actual resolution
  61.  * on the gs command line.
  62.  *
  63.  * If the preprocessor symbol A4 is defined, the default paper size is
  64.  * the European A4 size; otherwise it is the U.S. letter size (8.5"x11").
  65.  *
  66.  * To determine the proper "margin" settings for your printer, see the
  67.  * file align.ps.
  68.  */
  69.  
  70. /* Define the default, maximum resolutions. */
  71. #ifdef X_DPI
  72. #  define X_DPI2 X_DPI
  73. #else
  74. #  define X_DPI 300
  75. #  define X_DPI2 600
  76. #endif
  77. #ifdef Y_DPI
  78. #  define Y_DPI2 Y_DPI
  79. #else
  80. #  define Y_DPI 300
  81. #  define Y_DPI2 600
  82. #endif
  83.  
  84. /*
  85.  * For all DeskJet Printers:
  86.  *
  87.  *  Maximum printing width               = 2400 dots = 8"
  88.  *  Maximum recommended printing height  = 3100 dots = 10 1/3"
  89.  *
  90.  * All Deskjets have 1/2" unprintable bottom margin.
  91.  * The recommendation comes from the HP Software Developer's Guide for
  92.  * the DeskJet 500, DeskJet PLUS, and DeskJet printers, version C.01.00
  93.  * of 12/1/90.
  94.  *
  95.  * Note that the margins defined just below here apply only to the DeskJet;
  96.  * the paper size, width and height apply to the LaserJet as well.
  97.  */
  98.  
  99. /* Margins are left, bottom, right, top. */
  100. /* from Frans van Hoesel hoesel@rugr86.rug.nl. */
  101. /* A4 has a left margin of 1/8 inch and at a printing width of
  102.  * 8 inch this give a right margin of 0.143. The 0.09 top margin is
  103.  * not the actual margin - which is 0.07 - but compensates for the
  104.  * inexact paperlength which is set to 117 10ths.
  105.  * Somebody should check for letter sized paper. I left it at 0.07".
  106.  */
  107. #define DESKJET_MARGINS_LETTER  0.2, 0.45, 0.3, 0.05
  108. #define DESKJET_MARGINS_A4    0.125, 0.5, 0.143, 0.09
  109. /* Similar margins for the LaserJet. */
  110. /* These are defined in the PCL 5 Technical Reference Manual. */
  111. /* Note that for PCL 5 printers, we get the printer to translate the */
  112. /* coordinate system: the margins only define the unprintable area. */
  113. #define LASERJET_MARGINS_A4    0.167, 0.167, 0.167, 0.167
  114. #define LASERJET_MARGINS_LETTER    0.167, 0.167, 0.167, 0.167
  115.  
  116. /* See gdevdljm.h for the definitions of the PCL_ features. */
  117.  
  118. /* The device descriptors */
  119. private dev_proc_open_device(hpjet_open);
  120. private dev_proc_close_device(hpjet_close);
  121. private dev_proc_print_page_copies(djet_print_page_copies);
  122. private dev_proc_print_page_copies(djet500_print_page_copies);
  123. private dev_proc_print_page_copies(fs600_print_page_copies);
  124. private dev_proc_print_page_copies(ljet_print_page_copies);
  125. private dev_proc_print_page_copies(ljetplus_print_page_copies);
  126. private dev_proc_print_page_copies(ljet2p_print_page_copies);
  127. private dev_proc_print_page_copies(ljet3_print_page_copies);
  128. private dev_proc_print_page_copies(ljet3d_print_page_copies);
  129. private dev_proc_print_page_copies(ljet4_print_page_copies);
  130. private dev_proc_print_page_copies(ljet4d_print_page_copies);
  131. private dev_proc_print_page_copies(lp2563_print_page_copies);
  132. private dev_proc_print_page_copies(oce9050_print_page_copies);
  133.  
  134. private const gx_device_procs prn_hp_procs =
  135. prn_params_procs(hpjet_open, gdev_prn_output_page, hpjet_close,
  136.          gdev_prn_get_params, gdev_prn_put_params);
  137.  
  138. const gx_device_printer gs_deskjet_device =
  139. prn_device_copies(prn_hp_procs, "deskjet",
  140.           DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  141.           X_DPI, Y_DPI,
  142.           0, 0, 0, 0,        /* margins filled in by hpjet_open */
  143.           1, djet_print_page_copies);
  144.  
  145. const gx_device_printer gs_djet500_device =
  146. prn_device_copies(prn_hp_procs, "djet500",
  147.           DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  148.           X_DPI, Y_DPI,
  149.           0, 0, 0, 0,        /* margins filled in by hpjet_open */
  150.           1, djet500_print_page_copies);
  151.  
  152. const gx_device_printer gs_fs600_device =
  153. prn_device_copies(prn_hp_procs, "fs600",
  154.           DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  155.           X_DPI2, Y_DPI2,
  156.           0.23, 0.0, 0.23, 0.04,      /* margins */
  157.           1, fs600_print_page_copies);
  158.  
  159. const gx_device_printer gs_laserjet_device =
  160. prn_device_copies(prn_hp_procs, "laserjet",
  161.           DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  162.           X_DPI, Y_DPI,
  163.           0.05, 0.25, 0.55, 0.25,    /* margins */
  164.           1, ljet_print_page_copies);
  165.  
  166. const gx_device_printer gs_ljetplus_device =
  167. prn_device_copies(prn_hp_procs, "ljetplus",
  168.           DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  169.           X_DPI, Y_DPI,
  170.           0.05, 0.25, 0.55, 0.25,    /* margins */
  171.           1, ljetplus_print_page_copies);
  172.  
  173. const gx_device_printer gs_ljet2p_device =
  174. prn_device_copies(prn_hp_procs, "ljet2p",
  175.           DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  176.           X_DPI, Y_DPI,
  177.           0.20, 0.25, 0.25, 0.25,    /* margins */
  178.           1, ljet2p_print_page_copies);
  179.  
  180. const gx_device_printer gs_ljet3_device =
  181. prn_device_copies(prn_hp_procs, "ljet3",
  182.           DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  183.           X_DPI, Y_DPI,
  184.           0.20, 0.25, 0.25, 0.25,    /* margins */
  185.           1, ljet3_print_page_copies);
  186.  
  187. const gx_device_printer gs_ljet3d_device =
  188. prn_device_copies(prn_hp_procs, "ljet3d",
  189.           DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  190.           X_DPI, Y_DPI,
  191.           0.20, 0.25, 0.25, 0.25,    /* margins */
  192.           1, ljet3d_print_page_copies);
  193.  
  194. const gx_device_printer gs_ljet4_device =
  195. prn_device_copies(prn_hp_procs, "ljet4",
  196.           DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  197.           X_DPI2, Y_DPI2,
  198.           0, 0, 0, 0,        /* margins */
  199.           1, ljet4_print_page_copies);
  200.  
  201. const gx_device_printer gs_ljet4d_device =
  202. prn_device_copies(prn_hp_procs, "ljet4d",
  203.           DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  204.           X_DPI2, Y_DPI2,
  205.           0, 0, 0, 0,        /* margins */
  206.           1, ljet4d_print_page_copies);
  207.  
  208. const gx_device_printer gs_lp2563_device =
  209. prn_device_copies(prn_hp_procs, "lp2563",
  210.           DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  211.           X_DPI, Y_DPI,
  212.           0, 0, 0, 0,        /* margins */
  213.           1, lp2563_print_page_copies);
  214.  
  215. const gx_device_printer gs_oce9050_device =
  216. prn_device_copies(prn_hp_procs, "oce9050",
  217.           24 * 10, 24 * 10,    /* 24 inch roll (can print 32" also) */
  218.           400, 400,        /* 400 dpi */
  219.           0, 0, 0, 0,        /* margins */
  220.           1, oce9050_print_page_copies);
  221.  
  222. /* Open the printer, adjusting the margins if necessary. */
  223. private int
  224. hpjet_open(gx_device * pdev)
  225. {                /* Change the margins if necessary. */
  226.     gx_device_printer *const ppdev = (gx_device_printer *)pdev;
  227.     const float *m = 0;
  228.     bool move_origin = true;
  229.  
  230.     if (ppdev->printer_procs.print_page_copies == djet_print_page_copies ||
  231.     ppdev->printer_procs.print_page_copies == djet500_print_page_copies
  232.     ) {
  233.     static const float m_a4[4] =
  234.     {DESKJET_MARGINS_A4};
  235.     static const float m_letter[4] =
  236.     {DESKJET_MARGINS_LETTER};
  237.  
  238.     m = (gdev_pcl_paper_size(pdev) == PAPER_SIZE_A4 ? m_a4 :
  239.          m_letter);
  240.     } else if (ppdev->printer_procs.print_page_copies == oce9050_print_page_copies ||
  241.            ppdev->printer_procs.print_page_copies == lp2563_print_page_copies
  242.     );
  243.     else {            /* LaserJet */
  244.     static const float m_a4[4] =
  245.     {LASERJET_MARGINS_A4};
  246.     static const float m_letter[4] =
  247.     {LASERJET_MARGINS_LETTER};
  248.  
  249.     m = (gdev_pcl_paper_size(pdev) == PAPER_SIZE_A4 ? m_a4 :
  250.          m_letter);
  251.     move_origin = false;
  252.     }
  253.     if (m != 0)
  254.     gx_device_set_margins(pdev, m, move_origin);
  255.     /* If this is a LJIIID, enable Duplex. */
  256.     if (ppdev->printer_procs.print_page_copies == ljet3d_print_page_copies)
  257.     ppdev->Duplex = true, ppdev->Duplex_set = 0;
  258.     if (ppdev->printer_procs.print_page_copies == ljet4d_print_page_copies)
  259.     ppdev->Duplex = true, ppdev->Duplex_set = 0;
  260.     return gdev_prn_open(pdev);
  261. }
  262.  
  263. /* hpjet_close is only here to eject odd numbered pages in duplex mode, */
  264. /* and to reset the printer so the ink cartridge doesn't clog up. */
  265. private int
  266. hpjet_close(gx_device * pdev)
  267. {
  268.     gx_device_printer *const ppdev = (gx_device_printer *)pdev;
  269.     int code = gdev_prn_open_printer(pdev, 1);
  270.  
  271.     if (code < 0)
  272.     return code;
  273.     if (ppdev->Duplex_set >= 0 && ppdev->Duplex)
  274.     fputs("\033&l0H", ppdev->file);
  275.     fputs("\033E", ppdev->file);
  276.     return gdev_prn_close(pdev);
  277. }
  278.  
  279. /* ------ Internal routines ------ */
  280.  
  281. /* The DeskJet can compress (mode 2) */
  282. private int
  283. djet_print_page_copies(gx_device_printer * pdev, FILE * prn_stream,
  284.                int num_copies)
  285. {
  286.     return dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
  287.                     300, PCL_DJ_FEATURES,
  288.                     "\033&k1W\033*b2M");
  289. }
  290. /* The DeskJet500 can compress (modes 2&3) */
  291. private int
  292. djet500_print_page_copies(gx_device_printer * pdev, FILE * prn_stream,
  293.               int num_copies)
  294. {
  295.     return dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
  296.                     300, PCL_DJ500_FEATURES,
  297.                     "\033&k1W");
  298. }
  299. /* The Kyocera FS-600 laser printer (and perhaps other printers */
  300. /* which use the PeerlessPrint5 firmware) doesn't handle        */
  301. /* ESC&l#u and ESC&l#Z correctly.                               */
  302. private int
  303. fs600_print_page_copies(gx_device_printer * pdev, FILE * prn_stream,
  304.             int num_copies)
  305. {
  306.     int dots_per_inch = (int)pdev->y_pixels_per_inch;
  307.     char real_init[60];
  308.  
  309.     sprintf(real_init, "\033*r0F\033&u%dD", dots_per_inch);
  310.     return dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
  311.                     dots_per_inch, PCL_FS600_FEATURES,
  312.                     real_init);
  313. }
  314. /* The LaserJet series II can't compress */
  315. private int
  316. ljet_print_page_copies(gx_device_printer * pdev, FILE * prn_stream,
  317.                int num_copies)
  318. {
  319.     return dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
  320.                     300, PCL_LJ_FEATURES,
  321.                     "\033*b0M");
  322. }
  323. /* The LaserJet Plus can't compress */
  324. private int
  325. ljetplus_print_page_copies(gx_device_printer * pdev, FILE * prn_stream,
  326.                int num_copies)
  327. {
  328.     return dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
  329.                     300, PCL_LJplus_FEATURES,
  330.                     "\033*b0M");
  331. }
  332. /* LaserJet series IIp & IId compress (mode 2) */
  333. /* but don't support *p+ or *b vertical spacing. */
  334. private int
  335. ljet2p_print_page_copies(gx_device_printer * pdev, FILE * prn_stream,
  336.              int num_copies)
  337. {
  338.     return dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
  339.                     300, PCL_LJ2p_FEATURES,
  340.                     "\033*r0F\033*b2M");
  341. }
  342. /* All LaserJet series IIIs (III,IIId,IIIp,IIIsi) compress (modes 2&3) */
  343. /* They also need their coordinate system translated slightly. */
  344. private int
  345. ljet3_print_page_copies(gx_device_printer * pdev, FILE * prn_stream,
  346.             int num_copies)
  347. {
  348.     return dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
  349.                     300, PCL_LJ3_FEATURES,
  350.                     "\033&l-180u36Z\033*r0F");
  351. }
  352. /* LaserJet IIId is same as LaserJet III, except for duplex */
  353. private int
  354. ljet3d_print_page_copies(gx_device_printer * pdev, FILE * prn_stream,
  355.              int num_copies)
  356. {
  357.     return dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
  358.                     300, PCL_LJ3D_FEATURES,
  359.                     "\033&l-180u36Z\033*r0F");
  360. }
  361. /* LaserJet 4 series compresses, and it needs a special sequence to */
  362. /* allow it to specify coordinates at 600 dpi. */
  363. /* It too needs its coordinate system translated slightly. */
  364. private int
  365. ljet4_print_page_copies(gx_device_printer * pdev, FILE * prn_stream,
  366.             int num_copies)
  367. {
  368.     int dots_per_inch = (int)pdev->y_pixels_per_inch;
  369.     char real_init[60];
  370.  
  371.     sprintf(real_init, "\033&l-180u36Z\033*r0F\033&u%dD", dots_per_inch);
  372.     return dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
  373.                     dots_per_inch, PCL_LJ4_FEATURES,
  374.                     real_init);
  375. }
  376. private int
  377. ljet4d_print_page_copies(gx_device_printer * pdev, FILE * prn_stream,
  378.              int num_copies)
  379. {
  380.     int dots_per_inch = (int)pdev->y_pixels_per_inch;
  381.     char real_init[60];
  382.  
  383.     sprintf(real_init, "\033&l-180u36Z\033*r0F\033&u%dD", dots_per_inch);
  384.     return dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
  385.                     dots_per_inch, PCL_LJ4D_FEATURES,
  386.                     real_init);
  387. }
  388. /* The 2563B line printer can't compress */
  389. /* and doesn't support *p+ or *b vertical spacing. */
  390. private int
  391. lp2563_print_page_copies(gx_device_printer * pdev, FILE * prn_stream,
  392.              int num_copies)
  393. {
  394.     return dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
  395.                     300, PCL_LP2563B_FEATURES,
  396.                     "\033*b0M");
  397. }
  398. /* The Oce line printer has TIFF compression */
  399. /* and doesn't support *p+ or *b vertical spacing. */
  400. private int
  401. oce9050_print_page_copies(gx_device_printer * pdev, FILE * prn_stream,
  402.               int num_copies)
  403. {
  404.     int code;
  405.  
  406.     /* Switch to HP_RTL. */
  407.     fputs("\033%1B", prn_stream);    /* Enter HPGL/2 mode */
  408.     fputs("BP", prn_stream);    /* Begin Plot */
  409.     fputs("IN;", prn_stream);    /* Initialize (start plot) */
  410.     fputs("\033%1A", prn_stream);    /* Enter PCL mode */
  411.  
  412.     code = dljet_mono_print_page_copies(pdev, prn_stream, num_copies,
  413.                     400, PCL_OCE9050_FEATURES,
  414.                     "\033*b3M");
  415.  
  416.     /* Return to HPGL/2 mode. */
  417.     fputs("\033%1B", prn_stream);    /* Enter HPGL/2 mode */
  418.     if (code == 0) {
  419.     fputs("PU", prn_stream);    /* Pen Up */
  420.     fputs("SP0", prn_stream);    /* Pen Select */
  421.     fputs("PG;", prn_stream);    /* Advance Full Page */
  422.     fputs("\033E", prn_stream);    /* Reset */
  423.     }
  424.     return code;
  425. }
  426.